<?php
class ModuleController extends Controller
{
    var $widKey = false;

    public function actionGrid_data()
    {        
        $data = Array();
        $cont = 0;
		$model = tbl_modulos:: model()->findAll('mod_estado=:keyPar', array(':keyPar'=>0));
        foreach($model as $value){
            $cont++;
            if($value->mod_tipob=='BINF')
                $detalle="BOLETA DE INFRAESTRUCTURA";
            else{
                if($value->mod_tipob=='BGES')
                    $detalle="BOLETA DE GESTION";
                else
                    $detalle="GENERAL";
            }
			$data[] = array('id'=>$cont, 'data'=>array(
				$value->mod_id,
				$value->mod_codigo,
				//'Parte '.$value->bpa_numparte,
				$value->mod_detalle,
                $detalle
				//$value->mod_tipob
				));
        }
        $allData = array('rows'=>$data);
        echo 'data = '.CJSON::encode($allData);        
	}
    public function actionSave_data()
    {
        $model = new tbl_modulos();
        $transaction = Yii::app()->db->beginTransaction();
        try{
            $model->attributes = $_POST;
            $model->mod_estado = 0;
            $this->widKey = $model->save();
            if($this->widKey){
                $transaction->commit();
                echo $model->mod_id;
            }
        }catch(Exception $e){
            $this->widKey = false;
        }
        if(!$this->widKey){
            $transaction->rollback();
            echo "Error system controller 'Module' in the action -> Add.";//.$_POST['mod_detalle']." ".$_POST[];
        }
    }
    public function actionEdit_data()
    {
        $transaction = Yii::app()->db->beginTransaction();
        try{
            $model = tbl_modulos::model()->find("mod_id=:keyId", array(':keyId'=>$_GET['id']));
            $model->attributes = $_POST;
            $this->widKey = $model->save();
            if($this->widKey){
                $transaction->commit();
                echo true;
            }
        }catch(Exception $e){
            $this->widKey = false;
        }
        if(!$this->widKey){
            $transaction->rollback();
            echo "Error system controller 'Module' in the action -> Edit.";
        }
    }
    public function actionErase_data()
    {
        $transaction = Yii::app()->db->beginTransaction();
        try{
            $model = tbl_modulos::model()->find("mod_id=:keyId", array(':keyId'=>$_GET['id']));
            $model->mod_estado = 1;
            $this->widKey = $model->save();
            if($this->widKey){
                $transaction->commit();
                echo true;
            }
        }catch(Exception $e){
            $this->widKey = false;
        }
        if(!$this->widKey){
            $transaction->rollback();
            echo "Error system controller 'Dpto' in the action -> Erase.";
        }
    }
}
?>